package com.ruoyi.cloudpc.service.impl;

import com.ruoyi.cloudpc.domain.CloudDevice;
import com.ruoyi.cloudpc.enums.DeviceStatusEnum;
import com.ruoyi.cloudpc.mapper.CloudDeviceMapper;
import com.ruoyi.cloudpc.service.ICloudDeviceService;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 设备Service业务层处理
 *
 * @author Ten
 * @date 2025-09-20
 */
@Service
public class CloudDeviceServiceImpl implements ICloudDeviceService {
    @Autowired
    private CloudDeviceMapper cloudDeviceMapper;

    /**
     * 查询设备
     *
     * @param orderId 设备主键
     * @return 设备
     */
    @Override
    public CloudDevice selectCloudDeviceByOrderId(Long orderId) {
        return cloudDeviceMapper.selectCloudDeviceByOrderId(orderId);
    }

    /**
     * 查询设备列表
     *
     * @param cloudDevice 设备
     * @return 设备
     */
    @Override
    public List<CloudDevice> selectCloudDeviceList(CloudDevice cloudDevice) {
        return cloudDeviceMapper.selectCloudDeviceList(cloudDevice);
    }
    @Override
    public List<CloudDevice> myDeviceList(CloudDevice cloudDevice) {
        return cloudDeviceMapper.myDeviceList(cloudDevice);
    }

    /**
     * 新增设备
     *
     * @param cloudDevice 设备
     * @return 结果
     */
    @Override
    public int insertCloudDevice(CloudDevice cloudDevice) {
        cloudDevice.setCreateByAndTime();
        cloudDevice.setStatus(DeviceStatusEnum.STATUS_ZC.getStatus());
        return cloudDeviceMapper.insertCloudDevice(cloudDevice);
    }

    /**
     * 修改设备
     *
     * @param cloudDevice 设备
     * @return 结果
     */
    @Override
    public int updateCloudDevice(CloudDevice cloudDevice) {
//        cloudDevice.setUpdateTime(DateUtils.getNowDate());
        cloudDevice.setUpdateByAndTime();
        return cloudDeviceMapper.updateCloudDevice(cloudDevice);
    }

    /**
     * 修改设备
     *
     * @param cloudDevice 设备
     * @return 结果
     */
    @Override
    public int updateDeviceId(CloudDevice cloudDevice) {
        cloudDevice.setUpdateByAndTime();
        return cloudDeviceMapper.updateDeviceId(cloudDevice);
    }

    /**
     * 批量删除设备
     *
     * @param statuss 需要删除的设备主键
     * @return 结果
     */
    @Override
    public int deleteCloudDeviceByStatuss(String[] statuss) {
        return cloudDeviceMapper.deleteCloudDeviceByStatuss(statuss);
    }

    /**
     * 删除设备信息
     *
     * @param status 设备主键
     * @return 结果
     */
    @Override
    public int deleteCloudDeviceByStatus(String status) {
        return cloudDeviceMapper.deleteCloudDeviceByStatus(status);
    }
}
